package com.jike.jkgame.data;

import java.io.Serializable;

import org.json.JSONObject;


public class UserResource implements Serializable{
	public ResourceType res;
	public int tid;
	public int sid;
	public int level;
	public int exp;
	public int attack;
	public int defense;
	public int star;
	public int type;
	public int add;
	public int cast;
	
	public static UserResource fromJSON(ResourceType type, JSONObject json) {
		if (json == null) {
			return null;
		}
		
		UserResource res = new UserResource();
		res.res = type;
		res.tid = json.optInt("tid");
		res.sid = json.optInt("sid");
		res.level = json.optInt("level");
		res.exp = json.optInt("exp");
		res.attack = json.optInt("attack");
		res.defense = json.optInt("defense");
		res.star = json.optInt("star");
		res.type = json.optInt("type");
		res.add = json.optInt("add", res.add);
		res.cast = json.optInt("cast", 1); // 上阵接口中没有cast属性
		return res;
	}

}
